<?php
namespace Admin\Controller;
use Common\Controller\AdminController;

class SsnewsController extends AdminController{
	private $ssnews_where="id in (3,4,5)";
	public function index(){
		$where = 'n.pid = 3';
		$where .= I('get.pid', -1) > -1 ? ' and n.pid=' . I('get.pid', 0, 'intval') :'';
		$where .= I('get.title') ? ' and n.title like "%' . I('get.title') . '%"' : '';
		$where .= I('get.status_query', -1) > -1 ? ' and n.status=' . I('get.status_query') : '';
		$where .= I('get.start_time') ? ' and n.times>=' . strtotime(I('get.start_time')) : '';
		$where .= I('get.end_time') ? ' and n.times<' . (strtotime(I('get.end_time')) + 24*3500) : '';
		
		$list = $this->getList('n.id,n.title,n.subtitle,n.times,n.view,n.sort,n.status,c.name', 'news n', $where, 
						'n.sort desc,n.id desc', true,12,"LEFT JOIN app_classify c on n.pid = c.id");

		$this->assign('list', $list);
		$classifyList = $this->getList('id,pid,name', 'classify', $this->ssnews_where, 'sort desc,id asc');
		$this->sortNode($classifyList, $result);
		$this->assign('classifyList', $result);
		$this->display();
	}
     public function add(){
		if(IS_POST){
//			if(!$_POST['pid']){
//				$this->returnResult(false,"请维护分类");
//			}
			$_baseInfo = new \Admin\Model\JsBaseModel();
			$_POST['js_cslb'] = $_baseInfo->getNameById(I("post.js_cslb_id",0));
			$_POST['js_csxm'] = $_baseInfo->getNameById(I("post.js_csxm_id",0));

			$_POST['pid'] = 3;
			$_POST['times'] = strtotime($_POST['times']);
			$result = $this->updateData($_POST, 'news');
			$this->returnResult($result);
		}else{
			$list_csfl= $this->getList('*', 'js_base', 'pid=1', 'sort desc,id asc');
			$this->assign('list_csfl', $list_csfl);
			$list_csxm= $this->getList('*', 'js_base', 'pid=6', 'sort desc,id asc');
			$this->assign('list_csxm', $list_csxm);
			$list = $this->getList('id,pid,name', 'classify', $this->ssnews_where, 'sort desc,id asc');
			$this->assign('list', $list);
			$this->display();
		}
	}
	public function edit(){
		if(IS_POST){
//			if(!$_POST['pid']){
//				$this->returnResult(false,"请维护分类");
//			}
			$_baseInfo = new \Admin\Model\JsBaseModel();
			$_POST['js_cslb'] = $_baseInfo->getNameById(I("post.js_cslb_id",0));
			$_POST['js_csxm'] = $_baseInfo->getNameById(I("post.js_csxm_id",0));

			$_POST['pid'] = 3;
			$_POST['pic'] = $_POST['pic'] ? $_POST['pic'] : '';
			$_POST['times'] = strtotime($_POST['times']);
			$result = $this->updateData($_POST, 'news', 2);
			$this->returnResult($result);
		}else{
			$info = $this->getInfo('*', 'news', 'id=' . I('get.id', 0, 'intval'));
			$this->assign('info', $info);
			$list_csfl= $this->getList('*', 'js_base', 'pid=1', 'sort desc,id asc');
			$this->assign('list_csfl', $list_csfl);
			$list_csxm= $this->getList('*', 'js_base', 'pid=6', 'sort desc,id asc');
			$this->assign('list_csxm', $list_csxm);
			$list = $this->getList('id,pid,name', 'classify', $this->ssnews_where, 'sort desc,id asc');
			$this->sortNode($list, $result);
			$this->assign('list', $result);
			$this->display('add');
		}
	}
	
	public function del(){
		$result = $this->deleteData(array('id' => I('get.id', 0, 'intval')), 'news');
		$this->returnResult($result);
	}
}